﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceProcess;
using System.Text;

namespace mds.Queue.MSMQServer
{
   internal class MSMQServiceFactory
    {
       internal ServiceBase[] CreateServiceGroup()
       {
           List<ServiceBase> serviceList = new List<ServiceBase>();
           var config = MSMQConfigManager.Instance.GetConfig();
           config.ServiceList.ForEach(a =>
           {
               //try
               //{
               Type classObject = Type.GetType(a.Type, true);
               var serviceClass = Activator.CreateInstance(classObject);
               serviceList.Add((ServiceBase)serviceClass);
               //}
               //catch (Exception ex)
               //{
                   
               //}
           });
           return serviceList.ToArray();
       }

     internal IMSMQProcess CreateDefaultProcessService()
     {
         var defaultService = MSMQConfigManager.Instance.GetConfig().ServiceList.Find(a => a.IsDefault);
         if (defaultService != null) {
             Type classObject = Type.GetType(defaultService.Type, true);
             var serviceClass = Activator.CreateInstance(classObject);
             return (IMSMQProcess)serviceClass;
         }
         return null;
     }
    }
}
